package com.good.gpsapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.GnssAntennaInfo;
import android.location.GnssClock;
import android.location.GnssMeasurement;
import android.location.GnssMeasurementsEvent;
import android.location.GnssStatus;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import com.google.android.material.math.MathUtils;
import com.permissionx.guolindev.PermissionX;
import com.permissionx.guolindev.callback.ExplainReasonCallback;
import com.permissionx.guolindev.callback.RequestCallback;
import com.permissionx.guolindev.request.ExplainScope;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * https://blog.csdn.net/IT666DHW/article/details/133363441
 * https://wenmayi.com/post/28250.html
 *
 */
public class MainActivity extends AppCompatActivity {

    private final static String TAG = "LocationBeginActivity";

    public static String[] needPermissions = {
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
//            Manifest.permission.ACCESS_NETWORK_STATE,
//            Manifest.permission.CHANGE_NETWORK_STATE,
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
//            Manifest.permission.READ_PHONE_STATE
    };
    private ListView lv_data;
    private GnssAdapter gnssAdapter;
    private AppCompatTextView tv_count;
    private GpsSkyView gps;
    private AppCompatTextView tv_lat;
    private AppCompatTextView tv_time;
    private AppCompatTextView tv_lon;
    private AppCompatTextView ttff;
    private AppCompatTextView gao;
    private AppCompatTextView hv;
    private AppCompatTextView tv_msl;
    private AppCompatTextView ccount;
    private AppCompatTextView tv_speed;
    private AppCompatTextView tv_fangwei;
    private AppCompatTextView tv_speed_jingdu;
    private AppCompatTextView tv_fangwei_jingdu;
    private AppCompatTextView tv_pdop;
    private AppCompatTextView tv_dop;
    private Location locationInfo;


    private LocationManager manager;

    private List<GnssInfo>  date = new ArrayList<>();
    private GpsStatus.Listener gpsStatusListener = new GpsStatus.Listener() {
        @Override
        public void onGpsStatusChanged(int event) {
            switch (event) {
                //卫星状态改变
                case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
                    //获取当前状态
                    if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        // TODO: Consider calling
                        //    ActivityCompat#requestPermissions
                        // here to request the missing permissions, and then overriding
                        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                        //                                          int[] grantResults)
                        // to handle the case where the user grants the permission. See the documentation
                        // for ActivityCompat#requestPermissions for more details.
                        return;
                    }
                    GpsStatus gpsStatus = manager.getGpsStatus(null);
                    //获取卫星颗数的默认最大值
                    int maxSatellites = gpsStatus.getMaxSatellites();
                    //获取所有的卫星
                    Iterator<GpsSatellite> iters = gpsStatus.getSatellites().iterator();
                    //卫星颗数统计
                    int count = 0;
                    StringBuilder sb = new StringBuilder();
                    while (iters.hasNext() && count <= maxSatellites) {
                        count++;
                        GpsSatellite s = iters.next();
                        //卫星的信噪比
                        float snr = s.getSnr();
                        //卫星的方位角
                        float azimuth = s.getAzimuth();
                        //卫星的高度
                        float elevation = s.getElevation();
                        //卫星的方位角
                        float prn = s.getPrn();
                        StringBuilder mark = new StringBuilder();
                        //卫星的星历;天体位置表；星历表；历书；日历；日记
                        boolean ephemeris = s.hasEphemeris();
                        if(ephemeris){
                            mark.append("E");
                        }
                        //卫星的历书;年鉴;年历;星历;万年历
                        boolean Almanac = s.hasAlmanac();
                        if(Almanac){
                            mark.append("A");
                        }
                        //卫星是否修复中
                        boolean usedInFix = s.usedInFix();
                        if(usedInFix){
                            mark.append("U");
                        }
                        sb.append("第").append(count).append("颗").append("：").append("信噪比").append(":").append(snr).append("     ")
                                .append("方位角").append(":").append(azimuth).append("     ")
                                .append("高度").append(":").append(elevation).append("     ")
                                .append("prn").append(":").append(prn).append("     ")
                                .append("ephemeris").append(":").append(ephemeris).append("     ")
                                .append("Almanac").append(":").append(Almanac).append("     ")
                                .append("是否修复").append(":").append(usedInFix).append("     ")
                                .append("标识").append(":").append(mark.toString()).append("     ")
                                .append("\n");
                    }
                    Log.d(TAG, sb.toString());
                    break;
                default:
                    break;
            }
        }
    };

    /**
     * GnssMeasurementsEvent一个包含测量值数据的容器GnssClock包含GPS时钟时间戳记的类Gnssmeasurement代表GNSS卫星测量的类，其中包含原始信息和计算信息
     */
    @SuppressLint("NewApi")
    private GnssMeasurementsEvent.Callback gnssListener = new GnssMeasurementsEvent.Callback() {
        @Override
        public void onGnssMeasurementsReceived(GnssMeasurementsEvent eventArgs) {
            super.onGnssMeasurementsReceived(eventArgs);
            StringBuilder builder=new StringBuilder("GNSS测量数据：\n\n");
            builder.append(toStringClock(eventArgs.getClock()));
            builder.append("\n");
            for (GnssMeasurement measurement : eventArgs.getMeasurements()) {
                builder.append(toStringMeasurement(measurement));
                builder.append("\n");

            }
            Log.d(TAG,"eventArgs :"+ builder.toString());
        }

        @Override
        public void onStatusChanged(int status) {
            super.onStatusChanged(status);
            Log.d(TAG,"onStatusChanged status:"+status);
        }
    };

    @SuppressLint("NewApi")
    private String toStringClock(GnssClock gnssClock){
        //将GPS接收器时钟的值转换为字符串
        final String format = " %-4s = %s\n";
        StringBuilder builder=new StringBuilder("GNSS时钟:\n");
        //定义数据显示格式，“%-4”表示左对齐、不足四位补足四位 //定义格式化数字
        DecimalFormat numberFormat = new DecimalFormat("#0.000");
        //如果闰秒存在则显示闰秒
        if (gnssClock.hasLeapSecond()) {
            builder.append(String.format(format, "闰秒（LeapSecond）", gnssClock.getLeapSecond()));
        }
        builder.append(String.format(format, "硬件时钟（TimeNanos）", gnssClock.getTimeNanos()));
        //获取以毫秒为单位的GNSS接收器内部硬件时钟值
        if (gnssClock.hasTimeUncertaintyNanos()) {
            //获取硬件时钟的误差估计（不确定度）
            builder.append(String.format(format, "时钟误差估计（TimeUncertaintyNanos）", gnssClock.getTimeUncertaintyNanos()));
        }
        if (gnssClock.hasFullBiasNanos()) {
            //如果存在接收机本地时钟总偏差，则显示
            builder.append(String.format(format, "总时钟偏差（FullBiasNanos）", gnssClock.getFullBiasNanos()));
        }
        if (gnssClock.hasBiasNanos()) {
            //亚纳秒偏差
            builder.append(String.format(format, "亚偏差（BiasNanos）", gnssClock.getBiasNanos()));
        }
        if (gnssClock.hasBiasUncertaintyNanos()) {
            //FullBiasNanos和BiasNanos的误差估计
            builder.append(String.format(format, "时钟偏差估计（BiasUncertaintyNanos）", numberFormat.format(gnssClock.getBiasUncertaintyNanos())));
        }
        /** * 注意：以上五个数据用于计算GPS时钟 * 具体计算方法为：local estimate of GPS time = TimeNanos - (FullBiasNanos + BiasNanos) * 世界标准时：UtcTimeNanos = TimeNanos - (FullBiasNanos + BiasNanos) - LeapSecond * 1,000,000,000 */
        if (gnssClock.hasDriftNanosPerSecond()) {
            builder.append(String.format(format, "时钟漂移（DriftNanosPerSecond）", numberFormat.format(gnssClock.getDriftNanosPerSecond())));
        }
        if (gnssClock.hasDriftUncertaintyNanosPerSecond()) {
            builder.append(String.format(format, "时钟漂移估计（DriftUncertaintyNanosPerSecond）", numberFormat.format(gnssClock.getDriftUncertaintyNanosPerSecond())));
        }

        //获取硬件时钟不连续的计数,即：每当gnssclock中断时，该值+1
        builder.append(String.format(format, "中断计数（HardwareClockDiscontinuityCount）", gnssClock.getHardwareClockDiscontinuityCount()));
        return builder.toString();
    }

    //将GNSS测量结果转换为字符串
    @SuppressLint("NewApi")
    private String toStringMeasurement(GnssMeasurement measurement){
        //定义显示格式
        final String format = " %-4s = %s\n";
        StringBuilder builder = new StringBuilder("GNSS测量结果:\n");
        DecimalFormat numberFormat = new DecimalFormat("#0.000"); DecimalFormat numberFormat1 = new DecimalFormat("#0.000E00");
        //获取卫星ID
        /* 取决于卫星类型 * GPS：1-32
         *  SBAS：120-151、183-192
         *  GLONASS：OSN或FCN + 100之一
         *  1-24作为轨道槽号（OSN）（首选，如果知道） * 93-106作为频道号（FCN）（-7至+6）加100。
         * 即将-7的FCN编码为93，0编码为100，+ 6编码为106
         *  QZSS：193-200 * 伽利略：1-36 * 北斗：1-37
         */
        builder.append(String.format(format, "卫星ID", measurement.getSvid()));
        //获取卫星类型
        /** * 1:CONSTELLATION_GPS 使用GPS定位
         * 2:CONSTELLATION_SBAS 使用SBAS定位
         * 3：CONSTELLATION_GLONASS 使用格洛纳斯定位
         * 4：CONSTELLATION_QZSS 使用QZSS定位
         * 5：CONSTELLATION_BEIDOU 使用北斗定位 （^-^）!
         * 6：CONSTELLATION_GALILEO 使用伽利略定位
         * 7：CONSTELLATION_IRNSS 使用印度区域卫星定位 */
        builder.append(String.format(format, "卫星类型", measurement.getConstellationType()));
        //获取进行测量的时间偏移量（以纳秒为单位）
        builder.append(String.format(format, "测量时间偏移量", measurement.getTimeOffsetNanos()));
        //获取每个卫星的同步状态
        // 具体数值含义请查表
        builder.append(String.format(format, "同步状态", measurement.getState()));
        //获取时间戳的伪距速率，以m/s为单位
        builder.append( String.format( format, "伪距速率", numberFormat.format(measurement.getPseudorangeRateMetersPerSecond())));
        //获取伪距的速率不确定性（1-Sigma），以m/s为单位
        builder.append( String.format( format, "伪距速率不确定度", numberFormat.format(measurement.getPseudorangeRateUncertaintyMetersPerSecond())));
        if (measurement.getAccumulatedDeltaRangeState() != 0) {
            // 获取“累积增量范围”状态
            // 返回：MULTIPATH_INDICATOR_UNKNOWN（指示器不可用）=0
            // notice 即：指示器可用时，收集数据
            builder.append( String.format( format, "累积增量范围状态", measurement.getAccumulatedDeltaRangeState()));
            //获取自上次重置通道以来的累积增量范围，以米为单位.
            // 该值仅在上面的state值为“可用”时有效
            // notice 累积增量范围= -k * 载波相位（其中k为常数）
            builder.append( String.format( format, "累积增量范围", numberFormat.format(measurement.getAccumulatedDeltaRangeMeters())));
            //获取以米为单位的累积增量范围的不确定性（1-Sigma）
            builder.append( String.format( format, "累积增量范围不确定度", numberFormat1.format(measurement.getAccumulatedDeltaRangeUncertaintyMeters())));
        }
        if (measurement.hasCarrierFrequencyHz()) {//CF
            //获取被跟踪信号的载波频率
            builder.append( String.format(format, "信号载波频率", measurement.getCarrierFrequencyHz()));
        }
        if (measurement.hasCarrierCycles()) {
            //卫星和接收器之间的完整载波周期数
            builder.append(String.format(format, "载波周期数", measurement.getCarrierCycles()));
        }
        if (measurement.hasCarrierPhase()) {
            //获取接收器检测到的RF相位
            builder.append(String.format(format, "RF相位", measurement.getCarrierPhase()));
        }
        if (measurement.hasCarrierPhaseUncertainty()) {
            //误差估计
            builder.append( String.format( format, "RF相位不确定度", measurement.getCarrierPhaseUncertainty()));
        }
        //获取一个值，该值指示事件的“多路径”状态,返回0或1或2
        // MULTIPATH_INDICATOR_DETECTED = 1 测量显示有“多路径效应”迹象
        // MULTIPATH_INDICATOR_NOT_DETECTED = 2 测量结果显示没有“多路径效应”迹象
        builder.append(String.format(format, "多路经效应指示器", measurement.getMultipathIndicator()));
        if (measurement.hasSnrInDb()) {
            //获取信噪比（SNR），以dB为单位
            builder.append(String.format(format, "信噪比", measurement.getSnrInDb()));
        }
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            if (measurement.hasAutomaticGainControlLevelDb()) {
                //获取以dB为单位的自动增益控制级别
                builder.append(String.format(format, "自动增益控制级别", measurement.getAutomaticGainControlLevelDb()));
            }
            if (measurement.hasCarrierFrequencyHz()) {
                builder.append(String.format(format, "载波频率", measurement.getCarrierFrequencyHz()));
            }
        }

//        https://developer.android.google.cn/reference/android/location/GnssMeasurement#getAccumulatedDeltaRangeMeters()
        builder.append("getCodeType："+measurement.getCodeType()+"\n");
        builder.append("getAccumulatedDeltaRangeMeters ："+measurement.getAccumulatedDeltaRangeMeters ()+"\n");

//        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
//            if(measurement.hasBasebandCn0DbHz()){
//                builder.append("getBasebandCn0DbHz："+measurement.getBasebandCn0DbHz()+"\n");
//            }
//        }


        builder.append("getCn0DbHz："+measurement.getCn0DbHz()+"\n");
//        builder.append("getFullInterSignalBiasNanos："+measurement.getFullInterSignalBiasNanos()+"\n");

//        if(measurement.hasFullInterSignalBiasUncertaintyNanos()){
//            builder.append("getFullInterSignalBiasUncertaintyNanos："+measurement.getFullInterSignalBiasUncertaintyNanos()+"\n");
//        }

        builder.append("getReceivedSvTimeNanos："+measurement.getReceivedSvTimeNanos()+"\n");
//        builder.append("getReceivedSvTimeUncertaintyNanos："+measurement.getReceivedSvTimeUncertaintyNanos()+"\n");
//        if(measurement.hasSatelliteInterSignalBiasNanos()){
//            builder.append("getSatelliteInterSignalBiasNanos："+measurement.getSatelliteInterSignalBiasNanos()+"\n");
//        }
//        if(measurement.hasSatelliteInterSignalBiasUncertaintyNanos()){
//            builder.append("getSatelliteInterSignalBiasUncertaintyNanos："+measurement.getSatelliteInterSignalBiasUncertaintyNanos()+"\n");
//        }



//        measurement.getAccumulatedDeltaRangeMeters()

        return builder.toString();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lv_data = findViewById(R.id.lv_data);
        tv_count = findViewById(R.id.tv_count);
        gps = findViewById(R.id.gps);
        tv_lat = findViewById(R.id.tv_lat);
        tv_time = findViewById(R.id.tv_time);
        tv_lon = findViewById(R.id.tv_lon);
        ttff = findViewById(R.id.ttff);
        gao = findViewById(R.id.ttff);
        hv = findViewById(R.id.hv);
        tv_msl = findViewById(R.id.tv_msl);
        ccount = findViewById(R.id.ccount);
        tv_speed = findViewById(R.id.tv_speed);
        tv_fangwei = findViewById(R.id.tv_fangwei);
        tv_speed_jingdu = findViewById(R.id.tv_speed_jingdu);
        tv_fangwei_jingdu = findViewById(R.id.tv_fangwei_jingdu);
        tv_pdop = findViewById(R.id.tv_pdop);
        tv_dop = findViewById(R.id.tv_dop);
        initLocation();
    }

    @Override
    protected void onStart() {
        super.onStart();
        permissionX();
    }

    /**
     * 初始化定位管理
     */
    @SuppressLint("NewApi")
    private void initLocation() {
        manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        //判断GPS是否正常启动
        if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Toast.makeText(this, "请开启GPS导航", Toast.LENGTH_SHORT).show();
            //返回开启GPS导航设置界面
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivityForResult(intent, 0);
            return;
        }
        //添加卫星状态改变监听
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
//        manager.addGpsStatusListener(gpsStatusListener);


//        boolean is_register_success= manager.registerGnssMeasurementsCallback(gnssListener);
//        manager.registerGnssMeasurementsCallback(gnssListener, new Handler());
        //https://blog.csdn.net/x1471898145/article/details/119447177
        manager.registerGnssStatusCallback(new GnssStatus.Callback() {
            @Override
            public void onStarted() {
                super.onStarted();
            }

            @Override
            public void onFirstFix(int ttffMillis) {
                super.onFirstFix(ttffMillis);
            }

            @Override
            public void onSatelliteStatusChanged(@NonNull GnssStatus status) {
                super.onSatelliteStatusChanged(status);
                gps.setGnssStatus(status);
                Log.d(TAG,"共收到卫星信号："+status.getSatelliteCount());
                tv_count.setText("共收到卫星信号："+status.getSatelliteCount());
                date.clear();
                for(int i = 0;i<status.getSatelliteCount();i++){
                    GnssInfo gnssInfo = new GnssInfo();
                    StringBuilder mark = new StringBuilder();
                    if(status.hasAlmanacData(i)){
                        mark.append("A");
                    }
                    if(status.hasEphemerisData(i)){
                        mark.append("E");
                    }
                    if(status.usedInFix(i)){
                        mark.append("U");
                    }
                    gnssInfo.mark = mark.toString();
                    gnssInfo.country = getCountry(status.getConstellationType(i));
                    gnssInfo.cf = status.getCarrierFrequencyHz(i)+"";
                    gnssInfo.azimuth = status.getAzimuthDegrees(i)+"";
                    gnssInfo.elevation = status.getElevationDegrees(i)+"";
                    gnssInfo.id = status.getSvid(i)+"";
                    gnssInfo.cno = status.getCn0DbHz(i)+"";
                    StringBuilder builder = new StringBuilder("卫星信号 ");
                    builder.append("ID："+status.getSvid(i)).append("   高度："+status.getElevationDegrees(i))
                            .append("   方位角："+status.getAzimuthDegrees(i))
                            .append("   CF："+ status.getCarrierFrequencyHz(i))
                            .append("   C/NO："+status.getCn0DbHz(i))
                            .append("   国家："+getCountry(status.getConstellationType(i)))
                            .append("   标识："+mark)
                            .append("\n");
//                    Log.d(TAG,builder.toString());
                    date.add(gnssInfo);
                }
                showData();
            }
        });

        //1000位最小的时间间隔，1为最小位移变化；也就是说每隔1000ms会回调一次位置信息
//        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, new LocationListener() {
//            @Override
//            public void onLocationChanged(@NonNull Location location) {
//                Log.d(TAG,"location:"+location.toString());
//            }
//        });


        // 定义Criteria对象并设置为高精度模式
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
// 根据Criteria选择最佳提供者
        String providerName = manager.getBestProvider(criteria, false);

        if (providerName != null && !providerName.isEmpty()) {
            // 注册位置更新监听器
            LocationListener listener = new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    locationInfo = location;
                    double latitude = location.getLatitude();   // 经度
                    double longitude = location.getLongitude(); // 纬度
                    Log.d(TAG,"latitude:"+location.toString());
                    location.getBearing();
                    showTopInfo();
                    // 其他处理逻辑...
                }

                @Override
                public void onStatusChanged(String provider, int status, Bundle extras) {}

                @Override
                public void onProviderEnabled(String provider) {}

                @Override
                public void onProviderDisabled(String provider) {}
            };

            // 请求位置更新
            manager.requestLocationUpdates(providerName, 1000, 0, listener);
        } else {
            // GNSS不可用或未安装
            Log.e("TAG", "No suitable GPS provider found.");
        }
    }

    @SuppressLint("NewApi")
    private void showTopInfo(){
        tv_lat.setText(locationInfo.getLatitude()+"");
        tv_lon.setText(locationInfo.getLongitude()+"");
        tv_speed.setText(locationInfo.getSpeed()+"");
        tv_speed_jingdu.setText(locationInfo.getSpeedAccuracyMetersPerSecond()+"");
        tv_time.setText(locationInfo.getTime()+"");
        tv_fangwei.setText(locationInfo.getAccuracy()+"");
        tv_fangwei_jingdu.setText(locationInfo.getAccuracy()+"");
        gao.setText(locationInfo.getAltitude()+"");
    }

    private void showData(){
        if(gnssAdapter == null){
            gnssAdapter = new GnssAdapter(MainActivity.this,date);
            lv_data.setAdapter(gnssAdapter);
        }else {
            gnssAdapter.notifyDataSetChanged();
        }
    }

    private String getCountry(int type){
        /** * 1:CONSTELLATION_GPS 使用GPS定位
         * 2:CONSTELLATION_SBAS 使用SBAS定位
         * 3：CONSTELLATION_GLONASS 使用格洛纳斯定位
         * 4：CONSTELLATION_QZSS 使用QZSS定位
         * 5：CONSTELLATION_BEIDOU 使用北斗定位 （^-^）!
         * 6：CONSTELLATION_GALILEO 使用伽利略定位
         * 7：CONSTELLATION_IRNSS 使用印度区域卫星定位 */
        switch (type){
            case 1:
                return "美国";
            case 2:
                return "SBAS";
            case 3:
                return "俄罗斯";
            case 4:
                return "日本";
            case 5:
                return "中国";
            case 6:
                return "欧洲";
            case 7:
                return "印度";
        }
        return "";
    }

    private void permissionX(){
        PermissionX.init(this).permissions(needPermissions)
                .onExplainRequestReason(new ExplainReasonCallback() {
                    @Override
                    public void onExplainReason(@NonNull ExplainScope scope, @NonNull List<String> deniedList) {

                    }
                }).request(new RequestCallback() {
                    @Override
                    public void onResult(boolean allGranted, @NonNull List<String> grantedList, @NonNull List<String> deniedList) {
                        Log.d(TAG,"通过的权限如下：");
                        for(String a : grantedList){
                            Log.d(TAG,a);
                        }

                        Log.d(TAG,"拒绝的权限如下：");
                        for(String a : deniedList){
                            Log.d(TAG,a);
                        }
                    }
                });
    }

    @SuppressLint("NewApi")
    @Override
    protected void onDestroy() {
        super.onDestroy();
        manager.unregisterGnssMeasurementsCallback(gnssListener);
    }
}